/*
 * Copyright 2010. 
 * 
 * This document may not be reproduced, distributed or used 
 * in any manner whatsoever without the expressed written 
 * permission of xrkol Corp. 
 * 
 * $Rev: Rev $
 * $Author: Author $
 * $LastChangedDate: LastChangedDate $
 *
 */

package com.xrkol.sharelib.service.impl;

import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.xrkol.sharelib.dao.MessageRecordDao;
import com.xrkol.sharelib.entity.Message;
import com.xrkol.sharelib.entity.MessageRecord;
import com.xrkol.sharelib.entity.Student;
import com.xrkol.sharelib.service.MessageRecordService;

/**
 * @author peng.xia
 * 
 */
@Service
@Transactional
public class MessageRecordServiceImpl implements MessageRecordService {

    @Autowired
    private MessageRecordDao messageRecordDao;

    @Override
    public void save(MessageRecord entity) {
        this.messageRecordDao.save(entity);
    }

    @Override
    public void update(MessageRecord entity) {
        this.messageRecordDao.update(entity);
    }

    @Override
    public void delete(String id) {
        this.messageRecordDao.delete(id);
    }

    @Override
    public MessageRecord findById(String id) {
        return this.messageRecordDao.findById(id);
    }

    @Override
    public void saveByStudents(Set<Student> allStudents, Message message) {
        for (Student student : allStudents) {
            MessageRecord messageRecord = new MessageRecord();
            messageRecord.setStudent(student);
            messageRecord.setMessage(message);
            this.messageRecordDao.save(messageRecord);
        }

    }

}
